<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\logic\DepartmentLogic;
use think\facade\Request;

/**=========================================
 * Copyright © 2023-2024, WICMS.CN. All Rights Reserved
 * Project Name: WiCMS
 * Description: 部门控制器
 * Author: jason
 * Email: 52527998@QQ.COM
 * Date: 2024/12/14
 * Time: 23:57
 * File: app\admin\controller\Department.php
 * =========================================
 */
class Department extends BaseModule
{

    public function initialize(): void
    {
        parent::initialize();
    }

    public function get_list(): void
    {
        $condition = Request::post('');
        $list      = DepartmentLogic::getList($condition);
        $this->success('success', $list);
    }

    public function get_tree(): void
    {
        $condition = Request::post('');
        $list      = DepartmentLogic::getList($condition,['id','department_name','pid']);
        $this->success('success', $list);
    }

    public function save_data(): void
    {
        $data = Request::post();
        unset($data['higherDeptOptions']);
        $result = DepartmentLogic::saveData($data);
        if ($result === true) {
            $this->success('success');
        } else {
            $this->error($result);
        }
    }


    public function del_data(): void
    {
        $id = Request::get('id/d', 0);
        if (empty($id)) {
            $this->error('参数错误');
        }
        $result = DepartmentLogic::deleteData($id);
        if ($result !== true) {
            $this->error($result);
        } else {
            $this->success('success');
        }
    }

}